package com.immunology.service;

import java.sql.Date;
import java.util.*;

import com.immunology.dao.MedicineCardDao;
import com.immunology.dao.PatientDao;
import com.immunology.database.transformers.MedicineCardTransformer;
import com.immunology.database.transformers.PatientTransformer;
import com.immunology.model.MedicineCard;

public class CreateMedicineCardService {

	@SuppressWarnings("deprecation")
	public MedicineCard createMedicineCard(Map<String, String> parameters) {
		PatientDao patientDao = new PatientDao(new PatientTransformer());
		MedicineCard medicineCard = new MedicineCard();
		medicineCard.setPatientId(patientDao.getLastIdByPatient());
		Date createday = new Date(1);
		createday.setDate(Integer.parseInt(parameters.get("dayCreate")));
		createday.setMonth(Integer.parseInt(parameters.get("monthCreate"))-1);
		createday.setYear(Integer.parseInt(parameters.get("yearCreate"))-1900);
		medicineCard.setCreationDate(createday);
		medicineCard.setOtherPatientInfo(parameters.get("otherInfo"));
		MedicineCardDao medicineCardDao = new MedicineCardDao(new MedicineCardTransformer());
		medicineCardDao.insert(medicineCard);
		return medicineCard;
	}
}
